package com.chpro.http.yixin.verify;

import com.chpro.http.yixin.util.SHA1Util;
import lombok.extern.log4j.Log4j;

/**
 * 消息验证实体
 * Created by Administrator on 14-9-27.
 */
@Log4j
public class VerifyModel {


    /**
     * 易信加密签名，signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
     */
    private String signature;
    /**
     * 时间戳
     */
    private String timestamp;
    /**
     * 随机数
     */
    private String nonce;
    /**
     * 随机字符串
     */
    private String echostr;

    /**
     * 验证签名有效性
     * @return
     */
    public String verify(){
        log.info("进入易信验证签名有效性验证");
        String result = "";    //返回值
        String token = "abcd123";
        String content = token + timestamp + nonce;
        String tempSignature = SHA1Util.hex_sha1(content);
        log.info("原易信signature值:"+signature);
        log.info("易信签名SHA1加密后tempSignature值:"+tempSignature);
//        if(signature.equals(tempSignature)){
            result = echostr;
//        }else{
//            result = "error";
//        }
        log.info("进入易信验证签名有效性验证,返回result:"+result);
        return result;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getNonce() {
        return nonce;
    }

    public void setNonce(String nonce) {
        this.nonce = nonce;
    }

    public String getEchostr() {
        return echostr;
    }

    public void setEchostr(String echostr) {
        this.echostr = echostr;
    }

    public static void main(String[] args){
        VerifyModel verifyModel = new VerifyModel();
        verifyModel.setSignature("19fe7f4259d061eb1931a08ea7f7ee814553725f");
        verifyModel.setTimestamp("1411865567");
        verifyModel.setNonce("705932783576");
        verifyModel.setEchostr("819859");
        System.out.println(verifyModel.verify());
    }

}
